﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FWMS.DAO
{
    class ChanPinGuanLiDao
    {
        //查询全部
        public Bean.ChanPinGuanLiBean chanpinguanliDaoSelect()
        {
            DB.DBbase dbbase = new DB.DBbase();
            Bean.ChanPinGuanLiBean bean = new FWMS.Bean.ChanPinGuanLiBean();
            string sql = "";
            sql = "select chanpinname,chanpintype from chanpinguanli order by chanpinname, chanpintype";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length != 0)
                {
                    bean.Selectresult = dbbase.rows;
                    bean.Resultclo = dbbase.Col_Number;
                    bean.Resultrow = dbbase.Row_Number;
                }
                else
                {
                    bean.Selectresult = null;
                }
            }
            else
            {
                bean.Selectresult = null;
            }
            return bean;
        }
        //条件查询
        public Bean.ChanPinGuanLiBean chanpinguanliDaoSelectCondition(Bean.ChanPinGuanLiBean bean)
        {
            bool nameflag = false;
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "";
            sql = "select chanpinname,chanpintype from chanpinguanli where ";
            //条件产品名称
            if (!"".Equals(bean.Chanpinname))
            {
                sql = sql + "chanpinname LIKE '%" + bean.Chanpinname + "%'";
                nameflag = true;
            }
            //条件产品所需工期
            if ((!"".Equals(bean.Chanpintype)) && bean.Chanpintype != null)
            {
                if (nameflag)
                {
                    sql = sql + "and chanpintype = '" + bean.Chanpintype + "'";
                }
                else
                {
                    sql = sql + " chanpintype = '" + bean.Chanpintype + "'";
                }
            }
            sql = sql + "order by chanpinname,chanpintype ";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length != 0)
                {
                    bean.Selectresult = dbbase.rows;
                    bean.Resultclo = dbbase.Col_Number;
                    bean.Resultrow = dbbase.Row_Number;
                }
                else
                {
                    bean.Selectresult = null;
                }
            }
            else
            {
                bean.Selectresult = null;
            }
            return bean;
        }
        //添加
        public bool chanpinguanliDaoAdd(Bean.ChanPinGuanLiBean bean)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "";
            sql = "insert into chanpinguanli(chanpinname,chanpintype) values('" + bean.Chanpinname + "','" + bean.Chanpintype + "')";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.command())
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        //修改
        public bool chanpinguanliDaoModify(Bean.ChanPinGuanLiBean bean)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "";
            sql = "update chanpinguanli set chanpinname = '" + bean.Chanpinname + "',chanpintype = '" + bean.Chanpintype + "' where chanpinname='" + bean.Id + "'";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.command())
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
    }
}
